import { updateTopic } from '@/api/JobRecord'
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { getAllInformation,getInformationByType } from '@/api/TopicInformation.js'

// 创建一个新的 store 实例
export const topicStore = defineStore('topic', () => {
  const topic = ref({
    // id:'',topicContent:'',topicName:'',
    answers:[{
      // id:'',answerType:0,cementProportion:0,cementValue:0,deviationValue:0,gravelProportion:0,gravelValue:0,sandProportion:0,sandValue:0,
      // topicId:0,waterProportion:0,waterValue:0
    },{
      // id:'',answerType:1,cementProportion:0,cementValue:0,deviationValue:0,gravelProportion:0,gravelValue:0,sandProportion:0,sandValue:0,
      // topicId:0,waterProportion:0,waterValue:0
    },{
      // id:'',answerType:2,cementProportion:0,cementValue:0,deviationValue:0,gravelProportion:0,gravelValue:0,sandProportion:0,sandValue:0,
      // topicId:0,waterProportion:0,waterValue:0
    },{
      // id:'',answerType:3,cementProportion:0,cementValue:0,deviationValue:0,gravelProportion:0,gravelValue:0,sandProportion:0,sandValue:0,
      // topicId:0,waterProportion:0,waterValue:0
    }],
    topicInformations:[
      // {id:'',informationName:'',informationPath:'',informationType:''}
    ]
  })
  const Answer=ref({

  })
  //总的文件库表
  const TopicInfor = ref({

  })
  const topicOk = ref(false)
  const topicOk1 = ref(false)
  const topicOk2 = ref(false)
  const topicOk3 = ref(false)
  const topicOk4 = ref(false)
  const checkList = ref([])
  //封吧
  const GetAllTopicInfor = async()=>{
    const resa =  await getAllInformation()
    console.log(resa,111)
  }
  const GetTopicInforByType = async(type)=>{
    TopicInfor.value =  await getInformationByType(type)
  }
  //当前选定的题目所提供的文档
  const topicInformations = ref([{}])
  //确定当前是新增还是修改状态
  const isnew = ref(false)
//当前answers的下标，这里会根据你选择的答案变化数组下边有啦现在就是要把数组全都放进去对
const currentArray = ref(0)

  const updateTopic =  async(newTopic) => {
    currentArray.value = 0
    topic.value = newTopic 
    checkList.value = topic.value.topicInformations
    console.log(newTopic)}

  const updateAnswer = (v) =>{Answer.value = topic.value.answers.filter((item)=>item.answerType === v)}
  return {
    topic,
    updateTopic,
    Answer,
    updateAnswer,
    currentArray,
    isnew,
    TopicInfor,
    GetAllTopicInfor,
    GetTopicInforByType,
    checkList,
    topicOk,
    topicOk1,
    topicOk2,
    topicOk3,
    topicOk4
  }
//说真的其实理论上这种异步访问数据操作也应该写在这，然后其他位置调用才对，而不是每个页面都写一遍
})